package com.ssy.lingxi.logistics.controller;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.logistics.api.dto.request.CommonIdRequest;
import com.ssy.lingxi.logistics.model.request.ReceiverAddressAgentAddRequest;
import com.ssy.lingxi.logistics.model.request.ReceiverAddressAgentUpdateRequest;
import com.ssy.lingxi.logistics.model.request.ReceiverAddressListRequest;
import com.ssy.lingxi.logistics.model.response.ReceiverAddressAgentListResponse;
import com.ssy.lingxi.logistics.model.response.ReceiverAddressResponse;
import com.ssy.lingxi.logistics.service.IReceiverAddressAgentService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @menu 销售订单 - 代客下单 - 收货地址
 * @author yzc
 * @version 2.0.0
 * @date 2020/7/10
 */
@RestController
@RequestMapping("/logistics/receiverAddress/agent")
public class ReceiverAddressAgentController extends BaseController {

    @Resource
    private IReceiverAddressAgentService receiverAddressAgentService;

    /**
     * 收货地址分页列表
     * @param request 接口参数
     * @return 返回结果
     */
    @GetMapping("/page")
    public Wrapper<PageData<ReceiverAddressAgentListResponse>> pageReceiverAddress(ReceiverAddressListRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();
        return receiverAddressAgentService.pageReceiverAddress(request, sysUser);
    }

    /**
     * 收货地址添加
     *
     * @param request 接口参数
     * @return 返回结果
     */
    @PostMapping(value = "/add")
    public Wrapper<ReceiverAddressResponse> addReceiverAddress(@RequestBody @Validated ReceiverAddressAgentAddRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();
        return receiverAddressAgentService.addReceiverAddress(request, sysUser);
    }

    /**
     * 收货地址修改
     *
     * @param request 接口参数
     * @return 返回结果
     */
    @PostMapping(value = "/update")
    public Wrapper<Void> updateReceiverAddress(@RequestBody @Validated ReceiverAddressAgentUpdateRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();
        return receiverAddressAgentService.updateReceiverAddress(request, sysUser);
    }

    /**
     * 收货地址删除
     * @param request 接口参数
     * @return 返回结果
     */
    @PostMapping(value = "/delete")
    public Wrapper<Void> deleteReceiverAddress(@RequestBody CommonIdRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();
        return receiverAddressAgentService.deleteReceiverAddress(request, sysUser);
    }
}
